package org.spring.springboot.controller;

import java.util.List;

import org.spring.springboot.domain.City;
import org.spring.springboot.service.CityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

/**
 * Created by bysocket on 07/02/2017.
 */
@RestController
public class CityRestController {

    @Autowired
    private CityService cityService;

    @RequestMapping(value = "/api/city", method = RequestMethod.GET)
    public City findOneCity(@RequestParam(value = "cityName", required = true) String cityName) {
    	System.out.println("");
        return cityService.findCityByName(cityName);
    }
    @RequestMapping(value = "/api/cityId", method = RequestMethod.GET)
    public City findCityById(@RequestParam(value = "id", required = true) int id) {
    	System.out.println("");
    	return cityService.findCityById(id);
    }
    
    @RequestMapping("/query/{page}/{pageSize}")  
    public PageInfo query(@PathVariable Integer page, @PathVariable Integer pageSize) {  
        if(page!= null && pageSize!= null){  
            PageHelper.startPage(page, pageSize);  
        }  
        List<City> citys = cityService.getList();  
        return new PageInfo(citys);  	
    }  
    
    
    @RequestMapping(value = "/index", method = RequestMethod.GET)
    public String test( ) {
    	System.out.println("test");
    	return "hello";
    }

}
